import type { App } from 'vue'
import { createPinia, PiniaVuePlugin } from 'pinia'

const pinia = createPinia()

pinia.use(({ store }) => {
  const initialState = JSON.parse(JSON.stringify(store.$state))

  store.$reset = () => {
    store.$state = JSON.parse(JSON.stringify(initialState))
  }
})

export function setUpPinia(app: App) {
  app.use(PiniaVuePlugin)
}

export default pinia
